package com.github.llyb120.tools.ctrl;

import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.IdUtil;
import lombok.Cleanup;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * @Author: Administrator
 * @Date: 8/18/2021 4:50 PM
 */
@RequestMapping("/api/tools")
@RestController
public class UploadCtrl {


    @RequestMapping("upload")
    public void Upload(
        @RequestParam MultipartFile file
    ) throws IOException {
        File dir = new File("./upload");
        dir.mkdirs();
        @Cleanup OutputStream fos = new FileOutputStream(new File(dir, file.getOriginalFilename()));
        IoUtil.copy(file.getInputStream(), fos);
    }
}
